package com.xinchuang.controller.targetSystem;

import com.alibaba.fastjson.JSONObject;
import com.xinchuang.common.Result;
import com.xinchuang.fiter.NoToken;
import com.xinchuang.service.targetSystem.CommonService;
import com.xinchuang.service.targetSystem.IconService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @ClassName UtilController
 * @Description: TODO(工具controller)
 * @Author zhangxuan
 * @Date 2021-04-01 16:48
 * @Verion V1.0
 */
@Api(value = "工具controller", tags = {"工具接口"})
@RestController
public class UtilController {

    @Resource
    private IconService iconService;

    @Resource
    private CommonService commonService;

    private final String ICON_URL = "/icon/upload";

    private final String FILE_URL = "/file/upload";

    private final String PULL_LIST = "/target/pull";

    private final String SIGN_IMAGE = "/sign/list";

    private final String SIGN_IMAGE_ADD = "/sign/add";

    private final String SIGN_IMAGE_DELETE = "/sign/del";

    private final String SIGN_IMAGE_BINGDING = "/sign/binding";

    private final String ADD_RADIUS = "/radius/add";

    private final String GET_RADIUS = "/radius/get";

    @ApiOperation(value = "添加图片", notes = "添加图片信息")
    @PostMapping(ICON_URL)
    public Result<Map<String, Object>> addIcon(
            @RequestParam(value = "file") MultipartFile file) {
        return iconService.addIcon(file, false);
    }

    @ApiOperation(value = "添加文件", notes = "添加文件信息")
    @PostMapping(FILE_URL)
    public Result<Map<String, Object>> addFile(
            @RequestParam(value = "file") MultipartFile file) {
        return iconService.addFile(file);
    }

    @ApiOperation(value = "下列列表")
    @GetMapping(PULL_LIST)
    public Result<Map<String, Object>> pullDown(
            @RequestParam(value = "status") String status) {
        return commonService.selectSignData(status);
    }

    @ApiOperation(value = "获取标记列表")
    @GetMapping(SIGN_IMAGE)
    public Result getSignList(
            @RequestParam(value = "typeId", required = false) String typeId
    ) {
        return iconService.getSignList(typeId);
    }

    @ApiOperation(value = "添加标记图片", notes = "添加图片信息")
    @PostMapping(SIGN_IMAGE_ADD)
    public Result<Map<String, Object>> addSign(
            @RequestParam(value = "file") MultipartFile file) {
        return iconService.addIcon(file, true);
    }

    @ApiOperation(value = "删除标记图片")
    @DeleteMapping(SIGN_IMAGE_DELETE)
    public Result delSign(
            @RequestParam(value = "name") String name
    ) {
        return iconService.deleteSign(name);
    }

    @ApiOperation(value = "绑定标记图片")
    @PostMapping(SIGN_IMAGE_BINGDING)
    public Result bindingSign(@RequestBody JSONObject json) {
        String id = json.getString("id");
        String name = json.getString("name");
        return iconService.addSign(id, name);
    }

    @ApiOperation(value = "添加类型半径")
    @PostMapping(ADD_RADIUS)
    public Result addRadius(
            @RequestBody JSONObject json
    ) {
        String id = json.getString("id");
        Double radius = json.getDouble("radius");
        return commonService.addRadius(id, radius);
    }

    @ApiOperation(value = "获取类型半径")
    @GetMapping(GET_RADIUS)
    public Result<Map<String, Object>> getRadius(
            @RequestParam(value = "id") String id) {
        return commonService.getRadius(id);
    }

}